package hn.cch.caffeine.controller;

import hn.cch.caffeine.service.CaffeineService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value = "caffeine")
@RestController
public class CaffeineController {

    private static final Logger logger = LoggerFactory.getLogger(CaffeineController.class);

    @Autowired
    private CaffeineService caffeineService;

    @GetMapping(value = "getCache")
    public String getCache(@RequestParam(value = "key") String key) {
        logger.info("getCache key:{}", key);
        return caffeineService.getCache(key);
    }

    @GetMapping(value = "setCache")
    public String setCache(@RequestParam(value = "key") String key) {
        logger.info("setCache key:{}", key);
        return caffeineService.setCache(key);
    }

    @GetMapping(value = "delCache")
    public String delCache(@RequestParam(value = "key") String key) {
        logger.info("delCache key:{}", key);
        return caffeineService.delCache(key);
    }

    @GetMapping(value = "getCacheStats")
    public String getCacheStats() {
        return caffeineService.getCacheStats();
    }

    @GetMapping(value = "putCache")
    public String putCache(@RequestParam(value = "key") String key, @RequestParam(value = "value") String value) {
        logger.info("putCache key:{},value:{}", key, value);
        return caffeineService.putCache(key, value);
    }

}
